<?php
/** 
 * Copyright (c) 2012, Jiehun.com.cn Inc. All Rights Reserved
 * @author dengxiaolong@jiehun.com.cn
 * @date 2012-8-14
 * @version 1.0 
 * @brief 
 *  
 **/
// 补充正确的id和key
$appId = 10000;
$appKey = 'a5d16104be85fc85838ce2259c88f2cb';

$uris = array(
	'/cities' => array(),
	'/cates' => array(),
	'/store/lists' => array(),
	'/store/10004' => array(),
	'/dp/store/10004' => array(),
);

$secret = $appKey.'&';
require_once dirname(dirname(__FILE__)).'/UrlSign.php';
$us = new UrlSign();
foreach($uris as $uri => $params) {
	$params['app_id'] = $appId;
	$params['city_id'] = 110900;
	
	$params['app_usign'] = $us->makeSign('GET', $uri, $params, $secret);
	foreach($params as $key=>$value) {
		$params[$key] = $key.'='.rawurlencode($value);
	}
	$content = getUrl('http://192.168.0.249:8040/www/api'.$uri.'?'.implode('&', $params));
	var_dump(json_decode($content, true));
}

function getUrl($url)
{
	var_dump($url);
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_HEADER, 1);
	curl_setopt($curl, CURLOPT_URL, $url);
	ob_start();
	$ret = curl_exec($curl);
	$ret = ob_get_contents();
    ob_end_clean();
	curl_close($curl);
	$ret = explode("\n", $ret);
	if (strpos($ret[0], ' 200 ') !== false) {
		$str = array_shift($ret);
		while( $str && $str != "\r" ) {
			$str = array_shift($ret);
		}
		
		$ret = implode("\n", $ret);
		return $ret;
	} else {
		throw new Exception('error occurred. '.$ret[0]);
	}
}
